package com.itheima.service.Impl;

import com.itheima.common.entity.PageResult;
import com.itheima.mapper.CheckGroupMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckGroupServiceImpl implements CheckGroupService {
    @Autowired
    private CheckItemService checkItemService;
    @Autowired
    private CheckGroupMapper  checkGroupMapper;
    @Override
    public boolean addCheckGroup(CheckGroup checkGroup){
        return  checkGroupMapper.insert(checkGroup) > 0;
    }
    @Override
    public boolean delete(Integer id) {
        return checkGroupMapper.delete(id) > 0;
    }
    @Override
    public boolean updateCheckGroup(CheckGroup checkGroup) {
        return
                checkGroupMapper.update(checkGroup) > 0;
    }
    @Override
    public PageResult findPageByCode(Pageable pageable, String code) {
        int pageNum = pageable.getPageNumber();
        int pageSize = pageable.getPageSize();
        int offset = (pageNum - 1) * pageSize;
        List<CheckGroup> rows = checkGroupMapper.findByCode(code, offset, pageSize);
        long total = checkGroupMapper.countByCode(code);
        return new PageResult(total, rows);

    }
    @Override
    public PageResult findPageByName(Pageable pageable, String name) {
        int pageNum = pageable.getPageNumber();
        int pageSize = pageable.getPageSize();
        int offset = (pageNum - 1) * pageSize;
        List<CheckGroup> rows = checkGroupMapper.findByName(name, offset, pageSize);
        long total =  checkGroupMapper.countByName(name);
        return new PageResult(total, rows);
    }
    @Override
    public CheckGroup findById(Integer id) {
        return checkGroupMapper.findById(id);
    }
    @Override
    public PageResult findPageDefault(Pageable pageable) {
        int pageNum = pageable.getPageNumber();
        int pageSize = pageable.getPageSize();
        int offset = (pageNum - 1) * pageSize;
        List<CheckGroup> rows = checkGroupMapper.findPage(offset, pageSize);
        long total = checkGroupMapper.count();
        return new PageResult(total, rows);
    }
  @Override
    public List<String> findAll() {
        return checkGroupMapper.findAll();
    }



}
